using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using JGSY.CMS.LowCode.Platform.Application.Interfaces;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Controllers
{
    /// <summary>
    /// 系统设置管理控制器
    /// 提供系统设置项的增删改查、配置管理等API接口
    /// 支持系统参数配置、运行时设置调整、配置项分类管理等功能
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class SystemSettingController : ControllerBase
    {
        /// <summary>
        /// 系统设置应用服务接口
        /// </summary>
        private readonly ISystemSettingAppService _service;
        /// <summary>
        /// 构造函数，注入系统设置服务
        /// </summary>
        /// <param name="service">系统设置应用服务接口</param>
        public SystemSettingController(ISystemSettingAppService service)
        {
            _service = service;
        }
    /// <summary>
        /// 获取所有系统设置项
        /// </summary>
        /// <returns>系统设置项列表</returns>
    [HttpGet]
        public async Task<IEnumerable<SystemSettingDto>> GetAll() => await _service.GetAllAsync();
    /// <summary>
        /// 根据主键获取系统设置项
        /// </summary>
        /// <param name="id">设置项主键</param>
        /// <returns>系统设置项数据</returns>
    [HttpGet("{id}")]
        public async Task<SystemSettingDto?> GetById(long id) => await _service.GetByIdAsync(id);
    /// <summary>
        /// 添加系统设置项
        /// </summary>
        /// <param name="dto">系统设置项数据传输对象</param>
        /// <returns>操作结果</returns>
    [HttpPost]
        public async Task<IActionResult> Add(SystemSettingDto dto)
        {
            await _service.AddAsync(dto);
            return Ok();
        }
    /// <summary>
        /// 更新系统设置项
        /// </summary>
        /// <param name="id">设置项主键</param>
        /// <param name="dto">系统设置项数据传输对象</param>
        /// <returns>操作结果</returns>
    [HttpPut("{id}")]
        public async Task<IActionResult> Update(long id, SystemSettingDto dto)
        {
            await _service.UpdateAsync(id, dto);
            return Ok();
        }
    /// <summary>
        /// 删除系统设置项
        /// </summary>
        /// <param name="id">设置项主键</param>
        /// <returns>操作结果</returns>
    [HttpDelete("{id}")]
        public async Task<IActionResult> Delete(long id)
        {
            await _service.DeleteAsync(id);
            return Ok();
        }
    /// <summary>
        /// 根据分类获取系统设置项
        /// </summary>
        /// <param name="category">设置项分类</param>
        /// <returns>系统设置项列表</returns>
    [HttpGet("category/{category}")]
        public async Task<IEnumerable<SystemSettingDto>> GetByCategory(string category) => await _service.GetByCategoryAsync(category);
    }
}
